home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / dbm / mcom_db.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  14KB  |  464 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Netscape Public License
  6.  * Version 1.1 (the "License"); you may not use this file except in
  7.  * compliance with the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/NPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is 
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the NPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the NPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. /*- 
  40.  * Copyright (c) 1990, 1993, 1994
  41.  *    The Regents of the University of California.  All rights reserved.
  42.  *
  43.  * Redistribution and use in source and binary forms, with or without
  44.  * modification, are permitted provided that the following conditions
  45.  * are met:
  46.  * 1. Redistributions of source code must retain the above copyright
  47.  *    notice, this list of conditions and the following disclaimer.
  48.  * 2. Redistributions in binary form must reproduce the above copyright
  49.  *    notice, this list of conditions and the following disclaimer in the
  50.  *    documentation and/or other materials provided with the distribution.
  51.  * 3. All advertising materials mentioning features or use of this software
  52.  *    must display the following acknowledgement:
  53.  *    This product includes software developed by the University of
  54.  *    California, Berkeley and its contributors.
  55.  * 4. Neither the name of the University nor the names of its contributors
  56.  *    may be used to endorse or promote products derived from this software
  57.  *    without specific prior written permission.
  58.  *
  59.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  60.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  61.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  62.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  63.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  64.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  65.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  66.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  68.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  69.  * SUCH DAMAGE.
  70.  *
  71.  *    @(#)db.h    8.7 (Berkeley) 6/16/94
  72.  */
  73.  
  74. #ifndef _DB_H_
  75. #define    _DB_H_
  76.  
  77.  
  78. #ifdef WINCE
  79. #define off_t long
  80. #endif
  81.  
  82. #ifndef macintosh
  83. #include <sys/types.h>
  84. #endif
  85. #include "prtypes.h"
  86.  
  87. #include <limits.h>
  88.  
  89. #ifdef __DBINTERFACE_PRIVATE
  90.  
  91. #ifdef HAVE_SYS_CDEFS_H
  92. #include <sys/cdefs.h>
  93. #else
  94. #include "cdefs.h"
  95. #endif
  96.  
  97. #ifdef HAVE_SYS_BYTEORDER_H
  98. #include <sys/byteorder.h>
  99. #endif
  100.  
  101. #if defined(__linux) || defined(__BEOS__)
  102. #include <endian.h>
  103. #ifndef BYTE_ORDER
  104. #define BYTE_ORDER    __BYTE_ORDER
  105. #define BIG_ENDIAN    __BIG_ENDIAN
  106. #define LITTLE_ENDIAN __LITTLE_ENDIAN
  107. #endif
  108. #endif /* __linux */
  109.  
  110. #ifdef __sgi
  111. #define BYTE_ORDER BIG_ENDIAN
  112. #define BIG_ENDIAN      4321
  113. #define LITTLE_ENDIAN   1234            /* LSB first: i386, vax, all NT risc */
  114. #endif
  115.  
  116. #ifdef __sun
  117. #define BIG_ENDIAN      4321
  118. #define LITTLE_ENDIAN   1234            /* LSB first: i386, vax, all NT risc */
  119.  
  120. #ifndef __SVR4
  121. /* compat.h is only in 4.1.3 machines. - dp */
  122. #include <compat.h>
  123. #endif
  124.  
  125. /* XXX - dp
  126.  * Need to find a general way of defining endian-ness in SunOS 5.3
  127.  * SunOS 5.4 defines _BIG_ENDIAN and _LITTLE_ENDIAN
  128.  * SunOS 5.3 does nothing like this.
  129.  */
  130.  
  131. #ifndef BYTE_ORDER
  132.  
  133. #if defined(_BIG_ENDIAN)
  134. #define BYTE_ORDER BIG_ENDIAN
  135. #elif defined(_LITTLE_ENDIAN)
  136. #define BYTE_ORDER LITTLE_ENDIAN
  137. #elif !defined(__SVR4)
  138. /* 4.1.3 is always BIG_ENDIAN as it was released only on sparc platforms. */
  139. #define BYTE_ORDER BIG_ENDIAN
  140. #elif !defined(vax) && !defined(ntohl) && !defined(lint) && !defined(i386)
  141. /* 5.3 big endian. Copied this above line from sys/byteorder.h */
  142. /* Now we are in a 5.3 SunOS rather non 5.4 or above SunOS  */
  143. #define BYTE_ORDER BIG_ENDIAN
  144. #else
  145. #define BYTE_ORDER LITTLE_ENDIAN
  146. #endif
  147.  
  148. #endif /* !BYTE_ORDER */
  149. #endif /* __sun */
  150.  
  151. #if defined(__hpux) || defined(__hppa)
  152. #define BYTE_ORDER BIG_ENDIAN
  153. #define BIG_ENDIAN      4321
  154. #define LITTLE_ENDIAN   1234            /* LSB first: i386, vax, all NT risc */
  155. #endif
  156.  
  157. #if defined(AIXV3) || defined(AIX)
  158. /* BYTE_ORDER, LITTLE_ENDIAN, BIG_ENDIAN are all defined here */
  159. #include <sys/machine.h>
  160. #endif
  161.  
  162. /* Digital Unix */
  163. #ifdef __osf__
  164. #include <machine/endian.h>
  165. #endif
  166.  
  167. #ifdef __alpha
  168. #ifndef WIN32
  169. #else
  170. /* Alpha NT */
  171. #define BYTE_ORDER LITTLE_ENDIAN
  172. #define BIG_ENDIAN      4321
  173. #define LITTLE_ENDIAN   1234 
  174. #endif
  175. #endif
  176.  
  177. #ifdef NCR
  178. #include <sys/endian.h>
  179. #endif
  180.  
  181. #ifdef __QNX__
  182. #ifdef __QNXNTO__
  183. #include <sys/param.h>
  184. #else
  185. #define LITTLE_ENDIAN    1234
  186. #define BIG_ENDIAN    4321
  187. #define BYTE_ORDER    LITTLE_ENDIAN
  188. #endif
  189. #endif
  190.  
  191. #ifdef SNI
  192. /* #include <sys/hetero.h> */
  193. #define BYTE_ORDER BIG_ENDIAN
  194. #define BIG_ENDIAN      4321
  195. #define LITTLE_ENDIAN   1234
  196. #endif
  197.  
  198. #if defined(_WINDOWS) || defined(XP_OS2_VACPP)
  199. #ifdef BYTE_ORDER
  200. #undef BYTE_ORDER
  201. #endif
  202.  
  203. #define BYTE_ORDER LITTLE_ENDIAN
  204. #define LITTLE_ENDIAN   1234            /* LSB first: i386, vax, all NT risc */
  205. #define BIG_ENDIAN      4321
  206. #endif
  207.  
  208. #ifdef macintosh
  209. #define BIG_ENDIAN 4321
  210. #define LITTLE_ENDIAN 1234
  211. #define BYTE_ORDER BIG_ENDIAN
  212. #endif
  213.  
  214. #endif  /* __DBINTERFACE_PRIVATE */
  215.  
  216. #ifdef SCO
  217. #define MAXPATHLEN     1024              
  218. #endif
  219.  
  220. #include <fcntl.h>
  221.  
  222. #if defined(_WINDOWS) || defined(XP_OS2)
  223. #include <stdio.h>
  224. #include <io.h>
  225.  
  226. #ifndef XP_OS2 
  227. #define MAXPATHLEN     1024               
  228. #endif
  229.  
  230. #ifdef XP_OS2_VACPP
  231. #include <os2.h>
  232. #define    MAXPATHLEN    CCHMAXPATH
  233. #define    EPERM        EINVAL
  234. #define    ENOTDIR        EBADPOS
  235. #define    S_ISDIR(s)    ((s) & S_IFDIR)
  236. #endif
  237.  
  238. #define    EFTYPE        EINVAL        /* POSIX 1003.1 format errno. */
  239.  
  240. #ifndef    STDERR_FILENO
  241. #define    STDIN_FILENO    0        /* ANSI C #defines */
  242. #define    STDOUT_FILENO    1
  243. #define    STDERR_FILENO    2
  244. #endif
  245.  
  246. #ifndef O_ACCMODE            /* POSIX 1003.1 access mode mask. */
  247. #define    O_ACCMODE    (O_RDONLY|O_WRONLY|O_RDWR)
  248. #endif
  249. #endif
  250.  
  251. #ifdef macintosh
  252. #include <stdio.h>
  253. #include "xp_mcom.h"
  254. #define O_ACCMODE       3       /* Mask for file access modes */
  255. #define EFTYPE 2000
  256. PR_BEGIN_EXTERN_C
  257. int mkstemp(const char *path);
  258. PR_END_EXTERN_C
  259. #endif    /* MACINTOSH */
  260.  
  261. #if !defined(_WINDOWS) && !defined(macintosh)
  262. #include <sys/stat.h>
  263. #include <errno.h>
  264. #endif
  265.  
  266. /* define EFTYPE since most don't */
  267. #ifndef EFTYPE
  268. #define EFTYPE      EINVAL      /* POSIX 1003.1 format errno. */
  269. #endif
  270.  
  271. #define    RET_ERROR    -1        /* Return values. */
  272. #define    RET_SUCCESS     0
  273. #define    RET_SPECIAL     1
  274.  
  275. #define    MAX_PAGE_NUMBER    0xffffffff    /* >= # of pages in a file */
  276.  
  277. #ifndef __sgi
  278. typedef uint32    pgno_t;
  279. #endif
  280.  
  281. #define    MAX_PAGE_OFFSET    65535        /* >= # of bytes in a page */
  282. typedef uint16    indx_t;
  283. #define    MAX_REC_NUMBER    0xffffffff    /* >= # of records in a tree */
  284. typedef uint32    recno_t;
  285.  
  286. /* Key/data structure -- a Data-Base Thang. */
  287. typedef struct {
  288.     void    *data;            /* data */
  289.     size_t     size;            /* data length */
  290. } DBT;
  291.  
  292. /* Routine flags. */
  293. #define    R_CURSOR    1        /* del, put, seq */
  294. #define    __R_UNUSED    2        /* UNUSED */
  295. #define    R_FIRST        3        /* seq */
  296. #define    R_IAFTER    4        /* put (RECNO) */
  297. #define    R_IBEFORE    5        /* put (RECNO) */
  298. #define    R_LAST        6        /* seq (BTREE, RECNO) */
  299. #define    R_NEXT        7        /* seq */
  300. #define    R_NOOVERWRITE    8        /* put */
  301. #define    R_PREV        9        /* seq (BTREE, RECNO) */
  302. #define    R_SETCURSOR    10        /* put (RECNO) */
  303. #define    R_RECNOSYNC    11        /* sync (RECNO) */
  304.  
  305. typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
  306.  
  307. typedef enum { LockOutDatabase, UnlockDatabase } DBLockFlagEnum;
  308.  
  309. /*
  310.  * !!!
  311.  * The following flags are included in the dbopen(3) call as part of the
  312.  * open(2) flags.  In order to avoid conflicts with the open flags, start
  313.  * at the top of the 16 or 32-bit number space and work our way down.  If
  314.  * the open flags were significantly expanded in the future, it could be
  315.  * a problem.  Wish I'd left another flags word in the dbopen call.
  316.  *
  317.  * !!!
  318.  * None of this stuff is implemented yet.  The only reason that it's here
  319.  * is so that the access methods can skip copying the key/data pair when
  320.  * the DB_LOCK flag isn't set.
  321.  */
  322. #if UINT_MAX > 65535
  323. #define    DB_LOCK        0x20000000    /* Do locking. */
  324. #define    DB_SHMEM    0x40000000    /* Use shared memory. */
  325. #define    DB_TXN        0x80000000    /* Do transactions. */
  326. #else
  327. #define    DB_LOCK            0x2000    /* Do locking. */
  328. #define    DB_SHMEM        0x4000    /* Use shared memory. */
  329. #define    DB_TXN            0x8000    /* Do transactions. */
  330. #endif
  331.  
  332. /* Access method description structure. */
  333. typedef struct __db {
  334.     DBTYPE type;            /* Underlying db type. */
  335.     int (*close)    (struct __db *);
  336.     int (*del)    (const struct __db *, const DBT *, uint);
  337.     int (*get)    (const struct __db *, const DBT *, DBT *, uint);
  338.     int (*put)    (const struct __db *, DBT *, const DBT *, uint);
  339.     int (*seq)    (const struct __db *, DBT *, DBT *, uint);
  340.     int (*sync)    (const struct __db *, uint);
  341.     void *internal;            /* Access method private. */
  342.     int (*fd)    (const struct __db *);
  343. } DB;
  344.  
  345. #define    BTREEMAGIC    0x053162
  346. #define    BTREEVERSION    3
  347.  
  348. /* Structure used to pass parameters to the btree routines. */
  349. typedef struct {
  350. #define    R_DUP        0x01    /* duplicate keys */
  351.     uint32    flags;
  352.     uint    cachesize;    /* bytes to cache */
  353.     int    maxkeypage;    /* maximum keys per page */
  354.     int    minkeypage;    /* minimum keys per page */
  355.     uint    psize;        /* page size */
  356.     int    (*compare)    /* comparison function */
  357.         (const DBT *, const DBT *);
  358.     size_t    (*prefix)    /* prefix function */
  359.         (const DBT *, const DBT *);
  360.     int    lorder;        /* byte order */
  361. } BTREEINFO;
  362.  
  363. #define    HASHMAGIC    0x061561
  364. #define    HASHVERSION    2
  365.  
  366. /* Structure used to pass parameters to the hashing routines. */
  367. typedef struct {
  368.     uint    bsize;        /* bucket size */
  369.     uint    ffactor;    /* fill factor */
  370.     uint    nelem;        /* number of elements */
  371.     uint    cachesize;    /* bytes to cache */
  372.     uint32        /* hash function */
  373.         (*hash) (const void *, size_t);
  374.     int    lorder;        /* byte order */
  375. } HASHINFO;
  376.  
  377. /* Structure used to pass parameters to the record routines. */
  378. typedef struct {
  379. #define    R_FIXEDLEN    0x01    /* fixed-length records */
  380. #define    R_NOKEY        0x02    /* key not required */
  381. #define    R_SNAPSHOT    0x04    /* snapshot the input */
  382.     uint32    flags;
  383.     uint    cachesize;    /* bytes to cache */
  384.     uint    psize;        /* page size */
  385.     int    lorder;        /* byte order */
  386.     size_t    reclen;        /* record length (fixed-length records) */
  387.     uint8    bval;        /* delimiting byte (variable-length records */
  388.     char    *bfname;    /* btree file name */ 
  389. } RECNOINFO;
  390.  
  391. #ifdef __DBINTERFACE_PRIVATE
  392. /*
  393.  * Little endian <==> big endian 32-bit swap macros.
  394.  *    M_32_SWAP    swap a memory location
  395.  *    P_32_SWAP    swap a referenced memory location
  396.  *    P_32_COPY    swap from one location to another
  397.  */
  398. #define    M_32_SWAP(a) {                            \
  399.     uint32 _tmp = a;                        \
  400.     ((char *)&a)[0] = ((char *)&_tmp)[3];                \
  401.     ((char *)&a)[1] = ((char *)&_tmp)[2];                \
  402.     ((char *)&a)[2] = ((char *)&_tmp)[1];                \
  403.     ((char *)&a)[3] = ((char *)&_tmp)[0];                \
  404. }
  405. #define    P_32_SWAP(a) {                            \
  406.     uint32 _tmp = *(uint32 *)a;                \
  407.     ((char *)a)[0] = ((char *)&_tmp)[3];                \
  408.     ((char *)a)[1] = ((char *)&_tmp)[2];                \
  409.     ((char *)a)[2] = ((char *)&_tmp)[1];                \
  410.     ((char *)a)[3] = ((char *)&_tmp)[0];                \
  411. }
  412. #define    P_32_COPY(a, b) {                        \
  413.     ((char *)&(b))[0] = ((char *)&(a))[3];                \
  414.     ((char *)&(b))[1] = ((char *)&(a))[2];                \
  415.     ((char *)&(b))[2] = ((char *)&(a))[1];                \
  416.     ((char *)&(b))[3] = ((char *)&(a))[0];                \
  417. }
  418.  
  419. /*
  420.  * Little endian <==> big endian 16-bit swap macros.
  421.  *    M_16_SWAP    swap a memory location
  422.  *    P_16_SWAP    swap a referenced memory location
  423.  *    P_16_COPY    swap from one location to another
  424.  */
  425. #define    M_16_SWAP(a) {                            \
  426.     uint16 _tmp = a;                        \
  427.     ((char *)&a)[0] = ((char *)&_tmp)[1];                \
  428.     ((char *)&a)[1] = ((char *)&_tmp)[0];                \
  429. }
  430. #define    P_16_SWAP(a) {                            \
  431.     uint16 _tmp = *(uint16 *)a;                \
  432.     ((char *)a)[0] = ((char *)&_tmp)[1];                \
  433.     ((char *)a)[1] = ((char *)&_tmp)[0];                \
  434. }
  435. #define    P_16_COPY(a, b) {                        \
  436.     ((char *)&(b))[0] = ((char *)&(a))[1];                \
  437.     ((char *)&(b))[1] = ((char *)&(a))[0];                \
  438. }
  439. #endif
  440.  
  441. PR_BEGIN_EXTERN_C
  442. #if defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
  443. extern DB *
  444. #else
  445. PR_EXTERN(DB *)
  446. #endif
  447. dbopen (const char *, int, int, DBTYPE, const void *);
  448.  
  449. /* set or unset a global lock flag to disable the
  450.  * opening of any DBM file
  451.  */
  452. void dbSetOrClearDBLock(DBLockFlagEnum type);
  453.  
  454. #ifdef __DBINTERFACE_PRIVATE
  455. DB    *__bt_open (const char *, int, int, const BTREEINFO *, int);
  456. DB    *__hash_open (const char *, int, int, const HASHINFO *, int);
  457. DB    *__rec_open (const char *, int, int, const RECNOINFO *, int);
  458. void     __dbpanic (DB *dbp);
  459. #endif
  460.  
  461. PR_END_EXTERN_C
  462.  
  463. #endif /* !_DB_H_ */
  464.